<template>
  <header class="header">
    <div class="container">
      <div class="header-left">
        <!-- <h1 class="blog-title">我的博客</h1> -->
        <nav class="nav">
          <ul>
            <li><router-link to="/">首页</router-link></li>
            <li><router-link to="/categories">分类</router-link></li>
            <li><router-link to="/tags">标签</router-link></li>
            <li><router-link to="/archives">归档</router-link></li>
            <li><router-link to="/about">关于</router-link></li>
          </ul>
        </nav>
      </div>
      <div class="header-middle">
        <input type="text" class="search-input" placeholder="搜索文章" v-model="searchQuery" @keyup.enter="searchArticles" />
      </div>
      <div class="header-right">
        <div v-if="isLoggedIn">
          <img :src="userAvatar" alt="" class="user-avatar" />
          <span class="user-name">{{ userName }}</span>
          <button  class="register-btn" @click="logout">登出</button>
        </div>
        <div v-else>
          <button v-if="!isLoggedIn" class="login-btn" @click="login">登录</button>
        </div>
      </div>
    </div>
  </header>
</template>

<script setup >
import { ref } from 'vue';
  let searchQuery =ref('')
  let isLoggedIn = ref(false)
  let userAvatar = ref('https://tcmoshou.com/Public/static/image/my/banner/3.jpeg')
  let userName = ref('')
  function  login() {
    // 登录逻辑
    isLoggedIn.value = true;
    userName.value = "Kimi";
  }
  function logout(){
    isLoggedIn.value = false;
    userName.value = "";
  }
</script>

<style scoped>
.header {
  background-color: black;
  color: #fff;
  padding: 1rem 0;
}

.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.blog-title {
  font-size: 2rem;
  margin: 0;
}

.nav ul {
  list-style: none;
  display: flex;
  margin: 0;
  padding: 0;
}

.nav li {
  margin: 0 1rem;
}

.nav a {
  color: #fff;
  text-decoration: none;
}

.header-middle {
  flex: 1;
  display: flex;
  justify-content: center;
}

.search-input {
  width: 100%;
  max-width: 400px; /* 控制最大宽度 */
  padding: 0.75rem;
  border: none;
  border-radius: 4px;
  margin: 0 1rem;
  font-size: 1rem; /* 调整字体大小 */
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 0.5rem;
}

.user-name {
  font-weight: bold;
}

.login-btn,
.register-btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  background-color: #555;
  color: #fff;
  cursor: pointer;
  margin-left: 0.5rem;
}

.login-btn:hover,
.register-btn:hover {
  background-color: #777;
}
</style>